package com.gewu.pm.ui.activity.funds;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gewu.pm.R;
import com.gewu.pm.app.AppActivity;
import com.gewu.pm.bean.GoldBeanApprovalBean;
import com.gewu.pm.other.IntentKey;
import com.gewu.pm.ui.activity.approval.RejectionRecordActivity;
import com.gewu.pm.ui.adapter.funds.GoldBeanApprovalAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 金豆活动详情页面
 * 
 * 功能：
 * 1. 展示金豆申请基本信息
 * 2. 展示审批流程（时间轴样式）
 * 3. 根据 type 显示不同状态的审批流程
 */
public final class GoldBeanDetailsActivity extends AppActivity {

    // 基本信息
    private TextView mTerminalNameView;
    private TextView mGoldBeanCountView;
    private TextView mApplyReasonView;
    private TextView mInitiatorView;
    private TextView mInitiateTimeView;
    private TextView mEffectiveTimeView;

    // 审批流程
    private TextView mRejectRecordView;
    private RecyclerView mApprovalFlowView;
    private GoldBeanApprovalAdapter mApprovalAdapter;

    private String mType;  // 1=待审核，2=已通过，3=驳回

    public static void start(Context context, String type) {
        Intent intent = new Intent(context, GoldBeanDetailsActivity.class);
        intent.putExtra(IntentKey.TYPE, type);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.gold_bean_details_activity;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        // 基本信息
        mTerminalNameView = findViewById(R.id.tv_terminal_name);
        mGoldBeanCountView = findViewById(R.id.tv_gold_bean_count);
        mApplyReasonView = findViewById(R.id.tv_apply_reason);
        mInitiatorView = findViewById(R.id.tv_initiator);
        mInitiateTimeView = findViewById(R.id.tv_initiate_time);
        mEffectiveTimeView = findViewById(R.id.tv_effective_time);

        // 审批流程
        mRejectRecordView = findViewById(R.id.tv_reject_record);
        mApprovalFlowView = findViewById(R.id.rv_approval_flow);

        // 设置 RecyclerView
        mApprovalFlowView.setLayoutManager(new LinearLayoutManager(this));
        mApprovalAdapter = new GoldBeanApprovalAdapter(this);
        mApprovalFlowView.setAdapter(mApprovalAdapter);

        // 设置点击事件
        setOnClickListener(mRejectRecordView);
    }

    @Override
    protected void initData() {
        mType = getString(IntentKey.TYPE);
        loadApprovalFlow();
    }

    /**
     * 加载审批流程数据（根据type创建不同状态）
     * 
     * status: 0=待审批，1=已通过，2=已驳回
     */
    private void loadApprovalFlow() {
        List<GoldBeanApprovalBean> flowList = new ArrayList<>();

        // 前3条固定数据（都是已通过，status=1）
        flowList.add(new GoldBeanApprovalBean("2025/8/18 16:00", "翟辉·已提交", 1));
        flowList.add(new GoldBeanApprovalBean("2025/8/18 16:00", "陈浩·审核通过", 1));
        flowList.add(new GoldBeanApprovalBean("2025/8/18 16:00", "熊文尧·审核通过", 1));

        // 第4条数据根据type显示不同状态
        if ("1".equals(mType)) {
            // type=1：待审批（status=0）
            flowList.add(new GoldBeanApprovalBean("2025/8/18 16:00", "胡凌·待审批", 0));
        } else if ("2".equals(mType)) {
            // type=2：已通过（status=1）
            flowList.add(new GoldBeanApprovalBean("2025/8/18 16:00", "胡凌·审核通过", 1));
        } else if ("3".equals(mType)) {
            // type=3：已驳回（status=2）
            flowList.add(new GoldBeanApprovalBean("2025/8/18 16:00", "胡凌·已驳回", 2));
        }

        mApprovalAdapter.setData(flowList);
    }

    @Override
    public void onClick(android.view.View view) {
        super.onClick(view);
        if (view == mRejectRecordView) {
            // 点击驳回记录
            RejectionRecordActivity.start(getActivity());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 释放资源
    }
}
